﻿@model IceTea.Domain.Models.Release

@using(Ajax.BeginForm("EditRelease", "Product", new AjaxOptions(){
     HttpMethod = "Post",
     Confirm = "Are you sure you want to save the release?",
     Url = Url.Action("EditRelease", "Product"),
     UpdateTargetId = "editdialog",
     OnComplete = "OnComplete"
})){

<!-- the modal dialog for creating or editing the release -->    
@*<div class="modal fade" id="editdialog" role="dialog">*@
    <div class="modal-dialog">
        <div class="modal-content" id="editcontent">
        
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">@((Model == null || Model.Id <= 0)? "Create New Release" : "Edit Release" )</h4>
            </div>

            <div class="modal-body">
                <div class="control-group">@Html.ValidationSummary()</div>
        
                <div class="col-md-12 form-horizontal">            
                    <!-- Release Name -->
                    <div class="form-group">
                        @Html.LabelFor(r => r.Title, new { @class="control-label col-md-2"}) 
                        <div class="col-md-9">
                        @Html.TextBoxFor(r => r.Title, new{@class="form-control", @autofocus="autofocus"})
                        </div>
                        <div class="col-md-1"><span class="glyphicon glyphicon-asterisk"></span></div>
                    </div>
                    <!-- Release Description -->
                    <div class="form-group">
                        @Html.LabelFor(r => r.Description, new { @class="control-label col-md-2"})
                        <div class="col-md-9">
                        @Html.TextAreaFor(r => r.Description, 5, 20, 
                            new{@class="form-control"})
                    </div></div>

                    <!-- Start Date -->
                    <div class="form-group">
                        @Html.LabelFor(r => r.StartDate, new { @class="control-label col-md-2"})
                        <div class="col-md-9">
                            @Html.TextBoxFor(r => r.StartDate, "{0:D}", new{ @class="form-control"})
                        </div>
                        <div class="col-md-1"><span class="glyphicon glyphicon-asterisk"></span></div>
                    </div>

                    <!-- End Date -->
                    <div class="form-group">
                        @Html.LabelFor(r => r.EndDate, new { @class="control-label col-md-2"})
                        <div class="col-md-9">
                            @Html.TextBoxFor(r => r.EndDate, "{0:D}", new{ @class="form-control"})
                        </div>
                        <div class="col-md-1"><span class="glyphicon glyphicon-asterisk"></span></div>
                    </div>

                    <!-- hidden fields -->
                    <div class="form-group">
                        @Html.HiddenFor(r => r.Id)
                        @Html.HiddenFor(r => r.ProductId)
                    </div>
            </div>
        </div>

    <div class="modal-footer">
        <button type="submit" class="btn btn-primary">Save</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
    </div>

    </div>
    </div>
@*</div>*@
}

<script type="text/javascript">
    $(function(){
        $("#StartDate").datepicker();
        $("#EndDate").datepicker();
    });

    @if (ViewBag.Result == IceTea.Infrastructure.EditResult.Success)
    {
        @:$('#editdialog').modal('hide');
    }
    else if (ViewBag.Result == IceTea.Infrastructure.EditResult.Start)
    {
        @:$('#editdialog').modal('show');
    }
</script>